
clear
set mem 500m


**** Basic Time Series Figures
use "Data/all_patents_basicinfo.dta", clear


import delimited using "Data/BerkesGooglePatentDatabase/patents_fyear_iyear.csv", varnames(1) clear
duplicates drop patnum, force
save "Data/BerkesGooglePatentDatabase/patents_fyear_iyear.dta", replace

import delimited using "Data/BerkesGooglePatentDatabase/patents_ipc_categories.csv", varnames(1) clear
save "Data/BerkesGooglePatentDatabase/patents_ipc_classes.dta", replace

import delimited using "Data/BerkesGooglePatentDatabase/cit_received_long.csv", varnames(1) clear
save "Data/BerkesGooglePatentDatabase/cit_received_long.dta", replace
gen citationcount = 1
collapse (sum) citationcount, by(patnum)
save "Data/BerkesGooglePatentDatabase/citationcounts.dta", replace

import delimited using "Data/BerkesGooglePatentDatabase/patents_inventor_name_location.csv", varnames(1) colrange(1:2) clear
save "Data/BerkesGooglePatentDatabase/inventornames.dta", replace

import delimited using "Data/BerkesGooglePatentDatabase/patents_inventor_name_location.csv", varnames(1) colrange(10:10) clear
egen counter = seq()
save "Data/BerkesGooglePatentDatabase/inventornames2.dta", replace

import delimited using "Data/BerkesGooglePatentDatabase/patents_inventor_name_location.csv", varnames(1) colrange(18:18) clear
egen counter = seq()
save "Data/BerkesGooglePatentDatabase/inventornames3.dta", replace

import delimited using "Data/BerkesGooglePatentDatabase/patents_inventor_name_location.csv", varnames(1) colrange(26:26) clear
egen counter = seq()
save "Data/BerkesGooglePatentDatabase/inventornames4.dta", replace

import delimited using "Data/BerkesGooglePatentDatabase/patents_inventor_name_location.csv", varnames(1) colrange(34:34) clear
egen counter = seq()
save "Data/BerkesGooglePatentDatabase/inventornames5.dta", replace


import delimited using "Data/BerkesGooglePatentDatabase/patents_uspto_categories_11fix.csv", varnames(1) colrange(1:5) clear
egen counter = seq()
save "Data/BerkesGooglePatentDatabase/usptocodes.dta", replace


import delimited using "Data/BerkesGooglePatentDatabase/patents_inventor_name_location.csv", varnames(1) colrange(1:1) clear
egen counter = seq()
save "Data/BerkesGooglePatentDatabase/patentnumber.dta", replace

import delimited using "Data/BerkesGooglePatentDatabase/patents_inventor_name_location.csv", varnames(1) colrange(4:7) clear
egen counter = seq()
save "Data/BerkesGooglePatentDatabase/inventor1statecountry.dta", replace

import delimited using "Data/BerkesGooglePatentDatabase/patents_inventor_name_location.csv", varnames(1) colrange(14:15) clear
egen counter = seq()
save "Data/BerkesGooglePatentDatabase/inventor2statecountry.dta", replace

import delimited using "Data/BerkesGooglePatentDatabase/patents_inventor_name_location.csv", varnames(1) colrange(22:23) clear
egen counter = seq()
save "Data/BerkesGooglePatentDatabase/inventor3statecountry.dta", replace

use "Data/BerkesGooglePatentDatabase/patentnumber.dta", clear
merge 1:1 counter using "Data/BerkesGooglePatentDatabase/inventor1statecountry.dta"
drop _merge
merge 1:1 counter using "Data/BerkesGooglePatentDatabase/inventor2statecountry.dta"
drop _merge
merge 1:1 counter using "Data/BerkesGooglePatentDatabase/inventor3statecountry.dta"
drop _merge

save "Data/BerkesGooglePatentDatabase/googleinventorgeography.dta", replace


*** Open the Google patent class data set
use "Data/BerkesGooglePatentDatabase/patents_ipc_classes.dta", clear
keep patnum ipc0 ipc1 ipc2 
*** Merge in the uspto codes 
merge 1:1 patnum using "Data/BerkesGooglePatentDatabase/usptocodes.dta"
keep patnum ipc0 ipc1 ipc2 main_uspto 
*** Merge in the Google patent data set with the filing and grant years
merge 1:1 patnum using "Data/BerkesGooglePatentDatabase/patents_fyear_iyear.dta"
keep patnum ipc0 ipc1 ipc2 main_uspto fyear iyear imonth pyear
*** Merge in the Google patent data set with the inventor states of residence
merge 1:1 patnum using "Data/BerkesGooglePatentDatabase/googleinventorgeography.dta",
keep patnum ipc0 ipc1 ipc2 main_uspto fyear iyear imonth pyear inv_state1 inv_country1 inv_fips1 

split main_uspto, parse("/") gen(nclassgoogle)
destring nclassgoogle1, replace force

capture save "Data/BerkesGooglePatentDatabase/all_patents_basicinfo.dta", replace

